home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 23 / 0 / 3 / DISK2303.ZIP / SAMPLE.C < prev    next >
Text File  |  1989-11-08  |  5KB  |  169 lines

  1. /*-----------------------------------------------------------------------
  2. |            Sample.c                            |
  3. |                                    |
  4. |          This program is an example of how the C arrays of            |
  5. |       structures generated by Screen Machine can be displayed.     |
  6. |                                                                       |
  7. |          Note:                                                        |        
  8. |          Screen Machine always generates the structure "_scrn".  If   |
  9. |          you are including more than one screen generated by Screen   |
  10. |          Machine in a given program, only one declaration of the      |
  11. |          "_scrn" structure should be copied into the program.         |
  12. |                                                                       |
  13. |                                                                       |
  14. -----------------------------------------------------------------------*/
  15.  
  16. /*various include files*/
  17.  
  18. #include <stdio.h>
  19. #include <graph.h>
  20. #include <bios.h>
  21. #include <dos.h>
  22.  
  23. #define FALSE 0
  24. #define TRUE 1
  25. #define VIDEO 0x10                              /*Software interrupt 0x10 */
  26. #define WRITE_ATTR_CHAR 9                       /*Function 9 */
  27.  
  28.  
  29. void disp_screen(struct _scrn *, unsigned short );
  30.  
  31. struct _scrn    {
  32.         char    *chrs;
  33.         char    cw;
  34.         char    rw;
  35.         char    att;
  36.         };
  37.  
  38. struct _scrn screen_sample[]={
  39.     {"╔══════════════════════════════════════════════════════╗",14,7,31},
  40.     {"║                                                      ║",14,8,31},
  41.     {"║     ",14,9,31},
  42.     {"┌────────────────────────────────────────┐",20,9,121},
  43.     {"       ║",62,9,31},
  44.     {"║     ",14,10,31},
  45.     {"│",20,10,121},
  46.     {"                                        ",21,10,31},
  47.     {"│",61,10,121},
  48.     {"       ║",62,10,31},
  49.     {"║     ",14,11,31},
  50.     {"│",20,11,121},
  51.     {"  ",21,11,31},
  52.     {" testing this       ",23,11,122},
  53.     {"                  ",43,11,31},
  54.     {"│",61,11,121},
  55.     {"       ║",62,11,31},
  56.     {"║     ",14,12,31},
  57.     {"│",20,12,121},
  58.     {"  ",21,12,31},
  59.     {"    program         ",23,12,122},
  60.     {"                  ",43,12,31},
  61.     {"│",61,12,121},
  62.     {"       ║",62,12,31},
  63.     {"║     ",14,13,31},
  64.     {"│",20,13,121},
  65.     {"  ",21,13,31},
  66.     {"                    ",23,13,122},
  67.     {"                  ",43,13,31},
  68.     {"│",61,13,121},
  69.     {"       ║",62,13,31},
  70.     {"║     ",14,14,31},
  71.     {"│",20,14,121},
  72.     {"                                        ",21,14,31},
  73.     {"│",61,14,121},
  74.     {"       ║",62,14,31},
  75.     {"║     ",14,15,31},
  76.     {"└────────────────────────────────────────┘",20,15,121},
  77.     {"       ║",62,15,31},
  78.     {"║                                                      ║",14,16,31},
  79.     {"║                                                      ║",14,17,31},
  80.     {"╚══════════════════════════════════════════════════════╝",14,18,31},
  81.     {"  wow!!!    ",56,19,12},
  82.     {"            ",56,20,12},
  83.     {"\0",0,0,0}
  84.     };
  85.  
  86. struct _scrn screen_little[]={
  87.  
  88.     {"┌───────────────────┐",5,22,31},
  89.     {"│ Little ",5,23,31},
  90.     {"Window",14,23,121},
  91.     {"     │",20,23,31},
  92.     {"└───────────────────┘",5,24,31},
  93.     {"\0",0,0,0}
  94.     };
  95.  
  96.  
  97.  
  98.  
  99.  
  100. long color_back_grnd= 1;                                   /*All screens will use a blue background*/
  101.  
  102.  
  103. main()
  104. {
  105.  
  106.     disp_screen(screen_sample, TRUE);               /*Clear screen and then display the screen defined by screen_sample*/
  107.     disp_screen(screen_little, FALSE);              /*display screen defined by screen_little without clearing the screen */
  108.     _bios_keybrd(_KEYBRD_READ);            /*wait for a key*/
  109.  
  110. }
  111.  
  112. /*-----------------------------------------------------------
  113. | disp_screen - Use ptr passed to array of structures        |
  114. |        containing &text; col; row; and attribute.  |
  115. |        Use BIOS int 10h function 9 to display the  |
  116. |        data.                           |
  117. |                                |
  118. |        If cls_flag is TRUE, clear the screen before|
  119. |               displaying the data.  When clearing the     |
  120. |               screen, use the attribute defined in the    |
  121. |               variable color_back_grnd                    |
  122. |                                                           |
  123. |                                                           |
  124. |                                                           |
  125. ------------------------------------------------------------*/
  126.  
  127. void disp_screen(p, cls_flag)
  128. struct _scrn *p;
  129. unsigned short cls_flag;
  130. {
  131. char work;
  132. char wrow;
  133. char wcol;
  134. char * wsptr;
  135.  
  136. union REGS inregs, outregs;
  137.  
  138.  
  139.         if (cls_flag)
  140.         {
  141.                 _setbkcolor(color_back_grnd);
  142.                 _clearscreen(_GCLEARSCREEN);
  143.         }
  144.  
  145.     inregs.h.ah = WRITE_ATTR_CHAR;          /*print char and attribute*/
  146.     inregs.x.cx = 1;                /*Print 1 char*/
  147.  
  148.     while ( *(p->chrs) )
  149.     {
  150.         wsptr=p->chrs;                /*Get ptr to string*/
  151.         wcol=p->cw;
  152.  
  153.         inregs.h.bh = 0;               /*Video page 0*/
  154.         inregs.h.bl = p->att;                    /*Attribute to use */
  155.  
  156.         while (inregs.h.al = *wsptr++)          /*Char to print*/
  157.         {
  158.  
  159.                         /*Position the cursor*/
  160.  
  161.             _settextposition( (short) p->rw, (short) wcol++);             
  162.  
  163.             int86 ( VIDEO, &inregs, &outregs ); /*Print with BIOS*/
  164.         }
  165.  
  166.         p++;
  167.     }
  168. }
  169.